package cn.m3a1.service.student;

import cn.m3a1.bean.*;
import cn.m3a1.dao.AbsentNoteMapper;
import cn.m3a1.dao.CurseMapper;
import cn.m3a1.dao.TclassMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.PublicKey;
import java.util.List;

/**
 * @author wyj
 * @date 2019/7/13
 * @time 下午2:30
 */
@Service
public class StuFormService {
    @Autowired
    AbsentNoteMapper absentNoteMapper;
    @Autowired
    CurseMapper curseMapper;
    @Autowired
    TclassMapper tclassMapper;

    /**
     * 保存请假单
     * @param absentNote
     * @return
     */
    public Boolean  saveAbsentNote(AbsentNote absentNote){
        int insert = absentNoteMapper.insert(absentNote);
        return insert==1;
    }

    /**
     * 根据学生的id查询学生的课程信息
     * @param id
     * @return
     */
    public List<Curse> getCurses(int id){
        List<Curse> curses = curseMapper.selectByUserId(id);
        return curses;
    }

    /**
     * 根据学生id查询班级的信息
     * @param id
     * @return
     */
    public List<Tclass>  getTclass(int id){
        List<Tclass> tclasses = tclassMapper.selectByStuId(id);
        return  tclasses;
    }

    /**
     * 根据课程id获取课程信息
     * @param id
     * @return
     */
    public  List<Curse> getCurse(int id){
        CurseExample curseExample=new CurseExample();
        CurseExample.Criteria criteria = curseExample.createCriteria();
        criteria.andIdEqualTo(id);
        List<Curse> curses = curseMapper.selectByExample(curseExample);
        return curses;

    }

    /**
     * 根据学生的id获取id其所有所有的请假的信息
     *
     * @param id
     * @return
     */
    public  List<AbsentNote>  getMyleave(int id){
        AbsentNoteExample absentNoteExample=new AbsentNoteExample();
        AbsentNoteExample.Criteria criteria = absentNoteExample.createCriteria();
        criteria.andStudentidEqualTo(id);
        List<AbsentNote> absentNotes = absentNoteMapper.selectByExample(absentNoteExample);
        return  absentNotes;
    }

    /**
     * 允许学生在未审批时修改
     * @param id  传入假单的id
     * @return
     */
    public  boolean  delLeave(int id){
        AbsentNoteExample absentNoteExample=new AbsentNoteExample();
        AbsentNoteExample.Criteria criteria = absentNoteExample.createCriteria();
        criteria.andIdEqualTo(id);
        int i = absentNoteMapper.deleteByExample(absentNoteExample);
        return  i==1;

    }

}
